<template>
  <div>
    <router-view></router-view>
    <div class="container">
      <!--工具栏-->
      <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
        <el-form :inline="true" :model="filters" :size="size">
          <el-form-item>
            <el-input v-model="filters.name" placeholder="密钥"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button icon="fa fa-search" type="primary" @click="findPage(null)">搜索
            </el-button>
          </el-form-item>
          <el-form-item v-if="EditContor.orderedit">
            <el-button icon="fa fa-plus" type="primary" @click="handleAdd">添加
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
        <el-form :inline="true" :size="size">
          <el-form-item>
            <el-button-group>
              <el-tooltip content="刷新" placement="top">
                <el-button icon="fa fa-refresh" @click="findPage(null)">刷新</el-button>
              </el-tooltip>
            </el-button-group>
          </el-form-item>
        </el-form>
      </div>
      <!--表格内容栏-->
      <kt-table :data="pageResult" :columns="filterColumns" :showOperation="EditContor.orderedit"
                :showBatchDelete="EditContor.orderedit" opFrom="order"
                @findPage="findPage" @handleEdit="handleEdit" @handleDelete="handleDelete">
      </kt-table>

      <!--新增编辑界面-->
      <el-dialog :title="operation?'新增':'编辑'" width="40%" :visible.sync="dialogVisible" :close-on-click-modal="false">
        <el-form :model="dataForm" label-width="80px" :rules="dataFormRules" ref="dataForm" :size="size"
                 label-position="right">
          <el-form-item label="ID" prop="id" v-if="false">
            <el-input v-model="dataForm.id" :disabled="true" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="容量" prop="name">
            <el-input v-model="dataForm.capacity" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="nickName">
            <el-input v-model="dataForm.tips" auto-complete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button :size="size" @click.native="dialogVisible = false">{{"Cancel"}}</el-button>
          <el-button :size="size" type="primary" @click.native="submitForm" :loading="editLoading">{{"Submit"}}
          </el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import KtTable from "@/components/KtTable"
  import {
    format
  } from "@/utils/datetime"

  export default {
    name: 'orderPanel',
    components: {
      KtTable,
    },
    props: {
      EditContor: Object
    },
    data() {
      return {
        size: 'medium',
        filters: {
          name: ''
        },
        columns: [],
        filterColumns: [],
        pageRequest: {
          pageNum: 1,
          pageSize: 10
        },
        pageResult: {},
        operation: false, // true:新增, false:编辑
        dialogVisible: false, // 新增编辑界面是否显示
        editLoading: false,
        dataFormRules: {
          capacity: [{
            required: true,
            message: '请输入密钥',
            trigger: 'blur'
          }]
        },
        // 新增编辑界面数据
        dataForm: {
          capacity: 30,
          tips: '',
        },
      }
    }
    ,
    methods: {
      // 获取分页数据
      findPage: function (data) {
        let codepageInfo = {
          page: 1,
          size: 10
        }
        if (data !== null) {
          codepageInfo.page = data.pageRequest.pageNum
        }
        console.log(codepageInfo)
        this.$api.admin.getorderpage(codepageInfo).then((res) => {
          console.log(res.results)
          this.pageResult = res
        }).then(data != null ? data.callback : '')
      },
      // 批量删除
      handleDelete: function (data) {
        this.$message({message: '订单不允许修改', type: 'warning'})
      },
      // 显示新增界面
      handleAdd: function () {
        this.$message({message: '订单不允许修改', type: 'warning'})
      },
      // 显示编辑界面
      handleEdit: function (params) {
        this.$message({message: '订单不允许修改', type: 'warning'})
      },
      // 编辑
      submitForm: function () {
        this.$message({message: '订单不允许修改', type: 'warning'})
      },
      // 时间格式化
      dateFormat: function (row, column, cellValue, index) {
        console.log("formating!!")
        console.log(row[column.property])
        return format(row[column.property])
      },
      // 处理表格列过滤显示
      initColumns: function () {
        this.columns = [{
          prop: "username",
          label: "使用者",
          minWidth: 50
        }, {
          prop: "code",
          label: "密钥",
          minWidth: 70
        }, {
          prop: "capacity",
          label: "容量",
          minWidth: 50
        }, {
          prop: "createdate",
          label: "使用时间",
          minWidth: 80
        }
        ]
        this.filterColumns = JSON.parse(JSON.stringify(this.columns));
      }
    },
    mounted() {
      this.initColumns()
    }
  }
</script>

<style scoped lang="scss">
  .container {
    width: 50%;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 30px auto;
    /*width: 350px;*/
    padding: 35px 35px 45px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }

</style>
